import java.util.concurrent.TimeUnit;


/**
 * This class starts a new DRR round every few microseconds(defined by sleepIntervalMicros)
 * In each round, credits are assigned to various queues as defined by MDRRBuffer.startRound()
 *
 */
public class CreditsManager extends Thread {
	
	private MDRRBuffer buffer;
	private long sleepIntervalMicros;
	public CreditsManager(MDRRBuffer buffer, long sleepIntervalMicros)
	{
		this.buffer = buffer;
		this.sleepIntervalMicros = sleepIntervalMicros;
	}
	
	@Override
	public void run() {
		while(true)
		{
			buffer.startRound();
			try {
				TimeUnit.MICROSECONDS.sleep(sleepIntervalMicros);
			} catch (InterruptedException e) {
				e.printStackTrace();
				break;
			}
		}
	}

}
